/**
 * long description for the file
 *
 * @summary grunt 项目自动化构建
 * @author roy
 *
 * Created at     : 2020-07-10 13:00:39 
 * Last modified  : 2020-07-10 13:10:52
 */

const sass = require('sass');
const loadGruntTasks = require('load-grunt-tasks');

module.exports = grunt => {
    grunt.initConfig({
        sass: {
            options: {
                implementation: sass
            },
            main: {
                files: {
                    'dist/css/main.css': 'css/app.scss'
                }
            }
        },
        babel: {
            options: {
                sourceMap: true,
                presets: ['@babel/preset-env']  //根据最新的es特性进行转化
            },
            main: {
                files: {
                    'dist/js/app.js': 'js/app.js'
                }
            }
        },
        watch: { // 监听js,css文件变化
            js : {
                files: ['*.js'],
                tasks: ['babel']
            },
            css: {
                files: ['*.scss'],
                tasks: ['sass']
            }
        }
    })
    // grunt.loadNpmTasks('grunt-sass') // 将插件加载进来
    loadGruntTasks(grunt); // 自动加载所有grunt插件
    grunt.registerTask('default', ['sass','babel','watch'])
}